package cn.com.backstage.controller;

import java.io.PrintWriter;
import java.util.HashMap;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;




import cn.com.api.service.ICouponService;
import cn.com.util.JsonUtil;
import cn.com.util.PageInfo;
import cn.com.util.Util;
import cn.com.util.Utils;

@Controller
@RequestMapping(Utils.SYS_BACKSTAGE+"/")
public class CouponController {
	
	//日志
	private static Logger logger = Logger.getLogger(CouponController.class);
	
	@Autowired
	private ICouponService couponService;
	
	
	@RequestMapping(value = "coupon-list1")
	public ModelAndView coupon_list(HttpServletRequest request, 
			HttpServletResponse response, PageInfo pageInfo) throws Exception{		
		ModelAndView mv = new ModelAndView("forward:/backstage/coupon_list.jsp");
		Map<String,Object> conditions = new HashMap<String,Object>();
		
	//	List<ApiT_coupon_act> couponList = couponService.searchCouponList(conditions, pageInfo);
	//	mv.addObject("list", couponList);
	//	mv.addObject("pageInfo", pageInfo);
	//	mv.addObject("conditions", conditions);
		return mv;
	}
	

	@RequestMapping(value = "coupon-use-list1")
	public ModelAndView coupon_use_list(HttpServletRequest request, 
			HttpServletResponse response, PageInfo pageInfo) throws Exception{		
		ModelAndView mv = new ModelAndView("forward:/backstage/coupon_use_list.jsp");
		Map<String,Object> conditions = new HashMap<String,Object>();
		
	//	List<ApiT_coupon_act> couponList = couponService.searchCouponList(conditions, pageInfo);
	//	mv.addObject("list", couponList);
	//	mv.addObject("pageInfo", pageInfo);
	//	mv.addObject("conditions", conditions);
		return mv;
	}


	/**
	 * view
	 * @return
	 */
	@RequestMapping(value = "coupon-add-pre1")
	public ModelAndView coupon_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		ModelAndView mv = new ModelAndView("forward:/backstage/coupon_add_pre.jsp");
		return mv;
	}
	
	
	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "coupon-update1")
	public void coupon_update(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
	}
	
	
	@RequestMapping(value = "coupon-delete1")
	public void coupon_delete(HttpServletRequest request, HttpServletResponse response) throws Exception {

		
		Map<String, Object> map = new HashMap<String, Object>();
		try{
			String id = request.getParameter("id");
			logger.info("===========[CouponController[coupon_delete[id:"+id+"]]");
			couponService.deleteCouponById(id);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}catch(Exception e){
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.write(JsonUtil.object2json(map));
		out.close();
	}
}
